﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using JumpNFight.Simulation;
using Microsoft.Xna.Framework;
using XDL.Framework.Messaging;
using XDL.Framework;

namespace JumpNFight.Weapons
{
    class Disc :
        BalisticWeaponBase
    {
        int m_hitWallCount = 0;

        Moveable m_moveable;
        public override Moveable  Moveable
        {
            get
            {
                return m_moveable;
            }
        }

        public Disc(World world, int playerId, Vector2 position, Vector2 velocity) :
            base(world, playerId,position,velocity)
        {
            this.Lifetime = 10;
            m_moveable = new ElasticMoveable(GetNextID()) { Elasticity = 1f };
            m_moveable.Width = 16;
            m_moveable.Height = 2;
            m_moveable.GroundDrag = 10f;
            m_moveable.Position = position;
            m_moveable.Velocity = velocity;
            m_moveable.Mass = 0;
            m_moveable.MaxSpeed = 700;
            m_moveable.TileX = (int)Math.Floor(Moveable.X / World.UnitToPixel);
            m_moveable.TileY = (int)Math.Floor(Moveable.Y / World.UnitToPixel);
        }

        public override bool ProcessEvent(GameTime gameTime, int msgId, EventArgs e)
        {
            switch (msgId)
            {
                case World.HitBottomTileEvent:
                case World.HitLeftTileEvent:
                case World.HitTopTileEvent:
                case World.HitRightTileEvent:
                    m_hitWallCount++;
                    break;
            }

            if (m_hitWallCount > 1)
            {
                Kill();
                return true;
            }

            // default behavior if still active
            return base.ProcessEvent(gameTime, msgId, e);
        }
    }
}
